#include "stm32f10x.h"
#include "Delay.h"
#include "SoftSPI.h"
#include "SoftIIC.h"
#include "XPT2046.h"
#include "SDCard.h"
#include "FreeRTOS.h"
#include "Semphr.h"
#include "Queue.h"
#include "algorithm.h"
#include "Task.h"
#include "GUI.h"
#include "window.h"
#include "Chinese.h"
#include "ESP8266.h"
#include "EDP.h"
#include "MAX30102.h"
#include <cmath>
#include <exception>
#include <typeinfo>
#include <cstring>
#include <ctime>
using namespace std;
#define USART3_TXD Pin_10 //B
#define USART3_RXD Pin_11 //B
#define USART2_TXD Pin_2  //A
#define USART2_RXD Pin_3  //A
#define USART1_TXD Pin_9  //A
#define USART1_RXD Pin_10 //A
#define USART2_TX_DMA DMA1_Channel7
#define USART2_RX_DMA DMA1_Channel6
#define USART1_TX_DMA DMA1_Channel4
#define USART1_RX_DMA DMA1_Channel5
bool isSystemRun = false; //操作系统是否启动
bool isLogin = false;	  //是否已经登录
bool isTimerOn = false;
bool isConfigSucc = false;
TIM HeartBeat(TIM2);																			   //心跳定时器
USART cout(USART1, 115200), NetworkIO(USART2, 115200), BloodSensorIO(USART3, 115200);			   //调试接口对象
GPIO PA(GPIOA), PB(GPIOB), PC(GPIOC), PD(GPIOD), PE(GPIOE), PF(GPIOF), PG(GPIOG);				   //GPIO对象
EXTI MAXIntrrupt(12, EXTI_Trigger_Falling);														   //外部中断对象
SoftSPI sSPI(GPIO::Bit(GPIOF, 9), GPIO::Bit(GPIOB, 2), GPIO::Bit(GPIOF, 11), GPIO::Bit(GPIOB, 1)); //触摸屏接口对象
XPT2046 Touch(sSPI);																			   //触摸屏对象
SDCard Card(SDIO(178));																			   //储存器对象
DMA NetworkTx(DMA1_Channel7), NetworkRx(DMA1_Channel6), BloodPressure(DMA1_Channel3);			   //网络发送通道,网络接收通道,血压接收通道
ESP8266 Network(NetworkIO, NetworkRx);															   //网络对象
uint8_t *NetworkData;																			   //网络数据指针
uint16_t Data[4];																				   //测量结果
BloodInfo_t Blood;
// I2C MAXPort(I2C1, 0x7F, 1000);
SoftIIC MAXPort(GPIOB, 7, GPIOB, 6);
MAX30102 Heart(0x57, MAXPort, cout);
/*文件系统*/
FATFS fs;
FIL fil, font;
DIR dir;
FILINFO info;
FRESULT res;
/*信号量*/
SemaphoreHandle_t StartMesuare, NetworkRecive, NetworkSendDone; //开始测量信号量
SemaphoreHandle_t NewDataReady, uploadSucc;//MAX30102收到新数据
/*队列*/
QueueHandle_t NetworkUpload; //网络上传队列
/*********************************************************************************************************/

/*********************************************************************************************************/
void GPIO_Init()
{
	GPIO::InitTypeDef aaa;
	RCC::APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
	aaa.Speed = Speed_50MHz;
	//模拟输入模式

	//浮空输入模式
	aaa.Pin = USART1_RXD | USART2_RXD;
	aaa.Mode = Mode_IN_FLOATING;
	PA.Init(aaa);

	aaa.Pin = USART3_RXD;
	PB.Init(aaa);

	aaa.Pin = Pin_12;
	PG.Init(aaa);
	PG.EXTILineConfig(GPIO_PinSource12);

	//下拉输入模式

	//上拉输入模式
	aaa.Mode = Mode_IPU;
	aaa.Pin = Pin_2; //T_MISO
	PB.Init(aaa);

	

	//开漏输出模式

	//推挽输出模式
	aaa.Pin = Pin_0 | Pin_1; //LCD_BL T_SCK SD-CS
	aaa.Mode = Mode_Out_PP;
	PB.Init(aaa);

	aaa.Pin = Pin_9 | Pin_11; //T_MOSI|T_CS
	PF.Init(aaa);

	aaa.Pin = Pin_6 | Pin_7;
	PB.Init(aaa);

	//复用开漏模式
	aaa.Mode = Mode_AF_OD;
	
	//复用推挽模式
	aaa.Pin = USART1_TXD | USART2_TXD;
	aaa.Mode = Mode_AF_PP;
	PA.Init(aaa);

	aaa.Pin = USART3_TXD;
	PB.Init(aaa);

	aaa.Pin = Pin_8 | Pin_9 | Pin_10 | Pin_11 | Pin_12; //SDIO_D0-D3 SDIO_SCK
	PC.Init(aaa);

	aaa.Pin = Pin_2; //SDIO_CMD
	PD.Init(aaa);
}
void TIM_Init()
{
	TIM::TimeBaseInitTypeDef aaa;
	aaa.ClockDivision = TIM_CKD_DIV1;
	aaa.CounterMode = TIM_CounterMode_Up;
	aaa.Period = (50000 - 1);
	aaa.Prescaler = (7200 - 1);
	HeartBeat.Init(aaa);
}
void DMA_Init()
{
	NetworkIO.DMACmd(USART_DMAReq_Rx | USART_DMAReq_Tx, ENABLE); //允许网络对象发起Rx Tx DMA请求
	BloodSensorIO.DMACmd(USART_DMAReq_Rx, ENABLE);				 //允许血压传感器对象发起Rx DMA请求

	DMA::InitTypeDef aaa;
	aaa.M2M = DMA_M2M_Disable; //关闭内存到内存传输

	/*网络接收通道*/
	aaa.BufferSize = sizeof(Network.Buffer);							  //设置DMA传输数量为网络IO缓冲区大小
	aaa.DIR = DMA_DIR_PeripheralSRC;									  //传输方向 IO->存储器
	aaa.MemoryBaseAddr = (uint32_t)Network.Buffer;						  //内存地址 网络IO缓冲区
	aaa.MemoryDataSize = DMA_MemoryDataSize_Byte;						  //内存单元大小 字节
	aaa.MemoryInc = DMA_MemoryInc_Enable;								  //内存地址自增
	aaa.Mode = DMA_Mode_Normal;											  //传输模式 单次传输
	aaa.PeripheralBaseAddr = (uint32_t)&NetworkIO.GetPeriphPointer()->DR; //外设地址 网络IO对象DR寄存器
	aaa.PeripheralDataSize = DMA_PeripheralDataSize_Byte;				  //外设单元大小 字节
	aaa.PeripheralInc = DMA_PeripheralInc_Disable;						  //外设地址自增 关闭
	aaa.Priority = DMA_Priority_VeryHigh;								  //优先级 非常高
	NetworkRx.Init(aaa);												  //设定网络接收通道参数

	/*网络发送通道*/
	aaa.BufferSize = 0;													  //传输数量需要动态设置
	aaa.DIR = DMA_DIR_PeripheralDST;									  //传输方向 存储器->IO
	aaa.MemoryBaseAddr = 0;												  //内存地址需要动态设置
	aaa.MemoryDataSize = DMA_MemoryDataSize_Byte;						  //内存单元大小 字节
	aaa.MemoryInc = DMA_MemoryInc_Enable;								  //内存地址自增
	aaa.Mode = DMA_Mode_Normal;											  //传输模式 单次传输
	aaa.PeripheralBaseAddr = (uint32_t)&NetworkIO.GetPeriphPointer()->DR; //外设地址 网络IO对象DR寄存器
	aaa.PeripheralDataSize = DMA_PeripheralDataSize_Byte;				  //外设单元大小 字节
	aaa.PeripheralInc = DMA_PeripheralInc_Disable;						  //外设地址自增 关闭
	aaa.Priority = DMA_Priority_High;									  //优先级 高
	NetworkTx.Init(aaa);												  //设定网络发送通道参数

	/*血压接收通道*/
	aaa.BufferSize = sizeof(BloodInfo_t);									  //传输数量 BloodInfo_t大小
	aaa.DIR = DMA_DIR_PeripheralSRC;										  //传输方向 IO->存储器
	aaa.MemoryBaseAddr = (uint32_t)&Blood;									  //内存地址 Blood结构体
	aaa.MemoryDataSize = DMA_MemoryDataSize_Byte;							  //内存单元大小 字节
	aaa.MemoryInc = DMA_MemoryInc_Enable;									  //内存地址自增
	aaa.Mode = DMA_Mode_Circular;											  //传输模式 循环
	aaa.PeripheralBaseAddr = (uint32_t)&BloodSensorIO.GetPeriphPointer()->DR; //外设地址 血压传感器IO对象DR寄存器
	aaa.PeripheralDataSize = DMA_PeripheralDataSize_Byte;					  //外设单元大小 字节
	aaa.PeripheralInc = DMA_PeripheralInc_Disable;							  //外设地址自增 关闭
	aaa.Priority = DMA_Priority_Medium;										  //优先级 中等
	BloodPressure.Init(aaa);												  //设定血压传感器数据通道
	BloodPressure.On();														  //启动DMA通道
}
void Interrupt_Init()
{
	Interrupt::PriorityGroupConfig(NVIC_PriorityGroup_4);
	Interrupt::InitTypeDef aaa;
	aaa.NVIC_IRQChannelSubPriority = 14;
	aaa.NVIC_IRQChannelCmd = ENABLE;

	aaa.NVIC_IRQChannel = USART2_IRQn; //NetworkIO
	aaa.NVIC_IRQChannelCmd = ENABLE;
	aaa.NVIC_IRQChannelPreemptionPriority = 12;
	Interrupt::Init(aaa);
	NetworkIO.ITConfig(USART_IT_IDLE, ENABLE); //网络IO使能空闲中断

	aaa.NVIC_IRQChannel = DMA1_Channel7_IRQn; //NetworkTx
	aaa.NVIC_IRQChannelCmd = ENABLE;
	aaa.NVIC_IRQChannelPreemptionPriority = 14;
	Interrupt::Init(aaa);
	NetworkTx.ITConfig(DMA_IT_TC, ENABLE); //网络发送通道使能传输完成中断

	aaa.NVIC_IRQChannel = DMA1_Channel6_IRQn; //NetworkRx
	aaa.NVIC_IRQChannelCmd = ENABLE;
	aaa.NVIC_IRQChannelPreemptionPriority = 13;
	Interrupt::Init(aaa);
	NetworkRx.ITConfig(DMA_IT_TC, ENABLE); //网络接收通道使能传输完成中断

	aaa.NVIC_IRQChannel = TIM2_IRQn;
	aaa.NVIC_IRQChannelPreemptionPriority = 12;
	Interrupt::Init(aaa);
	HeartBeat.ITConfig(TIM_IT_Update, ENABLE);

	aaa.NVIC_IRQChannel = EXTI15_10_IRQn;
	aaa.NVIC_IRQChannelPreemptionPriority = 14;
	Interrupt::Init(aaa);
}
void DMA_Send(UpLoadPacket_t *Packet)
{
	NetworkTx.Off();
	NetworkTx.GetPeriphPointer()->CMAR = (uint32_t)Packet->Data; //设置数据地址
	NetworkTx.SetCurrDataCounter(Packet->Length);				 //设置传输数量
	NetworkTx.On();
}
void Login()
{
	UpLoadPacket_t Packet = {nullptr, 0};
	Packet.Length = EDP_login(&Packet.Data);
	if (Network.SendDataPrepare(Packet.Length))
	{
		DMA_Send(&Packet);
	}
	delete[] Packet.Data;
}
void TestUpload()
{
	UpLoadPacket_t Pack;
	Pack.Data = (uint8_t *)"Test";
	Pack.isDelete = false;
	Pack.Length = 0;
	xQueueSend(NetworkUpload, &Pack, portMAX_DELAY); //将数据包写入发送队列
}
/***************************************************************************/
void SensorTask(void *para)
{
	/*                 心率 血氧 高压 低压 */
	char buf[4][4];							   //测量结果字符串
	const static BloodInfo_t Request = {0xFD}; //查询命令
	while (true)
	{
		cout << "SENSOR" << endl;
		xSemaphoreTake(StartMesuare, portMAX_DELAY); //等待GUI发出开始测量信号
		memset(Data, 0x00, sizeof(Data));
		Delay.ms(500);
		for (char i = '5'; i >= '0'; i--) //倒计时5秒并显示
		{
			if (ExitMesuare)
				break; //用户中途退出
			char buf[] = {i, '\0'};
			TEXT_SetText(hTextMesuare[0], buf);
			Delay.ms(1000);
			BloodSensorIO.Send((uint8_t *)&Request, sizeof(Request)); //发送查询命令,预查询
		}
		if (ExitMesuare)
			continue;					   //如果中途退出,结束本次循环
		WM_HideWindow(hButtonExitMesuare); //未退出,接下来的过程禁止用户退出
		//开始测量
		for (int i = 0; i < 8; i++) //遍历设置要显示的文字
			TEXT_SetText(hTextMesuare[i], cn[i]);
		Delay.ms(1000);
		
		//获取血氧
		auto hbuf = new uint32_t[2][256];
		if(hbuf == nullptr)
		{
			cout<<"req mem fail"<<endl;
		}
		Heart.SetShutDown(false);
		for (int i = 0; i < 256;)
		{
			auto res = xSemaphoreTake(NewDataReady, 70);
			if (res == pdPASS)
			{
				//成功获取信号量
				auto Flag = Heart.GetInterruptFlag(0);
				Heart.GetInterruptFlag(1);
				if ((Flag & MAX30102::IT_New_FIFO_Data_Ready) == MAX30102::IT_New_FIFO_Data_Ready)
				{
					uint8_t buf[6];
					Heart.GetFIFOData(buf, 6);
					uint32_t data1, data2;
					data1 = (buf[0] << 16 | buf[1] << 8 | buf[2]) & 0x03ffff;
					data2 = (buf[3] << 16 | buf[4] << 8 | buf[5]) & 0x03ffff;
					// cout << data1 << ' ' << data2 << endl;
					auto dispData = data1-63000;
					if(dispData>0)
					{
						hbuf[0][i] = data1;
						hbuf[1][i] = data2;
						GRAPH_DATA_YT_AddValue(hData, dispData * 0.012f);
						i++;
					}
				}
			}
			else
			{
				cout << "Reset MAX30102" << endl;
				Heart.Reset();
				Delay.ms(50);
				Heart.DeInit();
				Delay.ms(50);
				Heart.SetShutDown(false);
			}
		}
		Heart.SetShutDown(true);
		int32_t spo2 = 0, red = 0;
		int8_t isSpo2V = 0, isRedV = 0;
		maxim_heart_rate_and_oxygen_saturation(hbuf[0], 256, hbuf[1], &spo2, &isSpo2V, &red, &isRedV);
		delete[] hbuf;
		cout.Printf("isSpo2V:%d\r\nisRedV:%d\r\nred:%d\r\nSpo2:%d\r\n", isSpo2V, isRedV, red, spo2);

		bool L, H;
		uint16_t tryTime = 0;
		BloodSensorIO.ReceiveData(); //读取DR寄存器以清除空闲标志位
		//获取心率+血压
		do
		{
			BloodSensorIO.Send((uint8_t *)&Request, sizeof(Request)); //发送查询命令
			while (not BloodSensorIO.GetFlagStatus(USART_FLAG_IDLE));//等待收到数据
			BloodSensorIO.ReceiveData(); //读取DR寄存器以清除空闲标志位
			L = ((Blood.HeartRate == 0) or (Blood.HighPressure == 0) or (Blood.LowPressure == 0));
			H = ((Blood.HeartRate == 255) or (Blood.HighPressure == 255) or (Blood.LowPressure == 255));
		} while ((L or H) and (tryTime++ < 65530));
		
		if (not (isSpo2V and isRedV and tryTime < 65530))
		{
			WM_ShowWindow(hButtonExitMesuare); //测量结束,允许用户退出
			continue;
		}
		cout << "TryTime:" << tryTime << endl;

		Data[0] = Blood.HeartRate;	  //读入心率
		Data[1] = spo2;				  //血氧
		Data[2] = Blood.HighPressure; //读入高压
		Data[3] = Blood.LowPressure;  //读入低压


		// Data[0] = 63;	  //读入心率
		// Data[1] = spo2;		//血氧
		// Data[2] = 126; //读入高压
		// Data[3] = 72;  //读入低压

		//展示结果
		for (int i = 0; i < 4; i++) //将数值转字符串
			snprintf(buf[i], 4, "%d", Data[i]);
		for (int i = 0; i < 4; i++) //显示字符串结果
			TEXT_SetText(hTextMesuare[i], buf[i]);
		Delay.ms(500 + rand() % 501); //随机延时

		//完成测量
		WM_ShowWindow(hButtonExitMesuare); //测量结束,允许用户退出
		WM_ShowWindow(hButtonUpload);	   //测量结束,显示上传按钮
	}
}
void srvNetworkTx(void *para)
{
	UpLoadPacket_t DataPointer; //要上传的数据
	while (true)
	{
		xQueueReceive(NetworkUpload, &DataPointer, portMAX_DELAY);	  //等待上传队列中数据有效
		cout << "NET TX" << endl;
		ESP8266::NET_Status_t NETStatus = Network.GetNetworkStatus(); //更新网络状态
		cout << "Network Status:" << ESP8266::NET_Status_String[NETStatus] << endl;
		Delay.ms(1000);
		switch (NETStatus)
		{
		case ESP8266::Error:
		case ESP8266::NoWIFI: //此类情况无法由程序解决,只能等待
			isLogin = false;
			isTimerOn = false;
			isConfigSucc = false;
			HeartBeat.Off();
			cout << "NetWork Upload Abort:" << ESP8266::NET_Status_String[NETStatus] << "Timer Off" << endl;
			break;

		case ESP8266::GetIP:
		case ESP8266::LostConnect: //此类情况需要建立TCP连接,再发送
			isLogin = false;
			cout << "Try Build TCP" << endl;
			if (not Network.BuildConnection("TCP", "jjfaedp.hedevice.com", 876)) //若和EDP服务器建立连接失败
			{
				cout << "Build TCP Fail" << endl;
				isTimerOn = false;
				HeartBeat.Off();
				break;			  //放弃上传
			}					  //否则继续执行
		case ESP8266::Connection: //此情况可以直接上传
			if (not isLogin)	  //如果设备还没登录
			{
				cout << "Login" << endl;
				Login(); //尝试登录
			}
			if (not isTimerOn) //如果心跳定时器没有打开
			{
				cout << "Timer On" << endl;
				isTimerOn = true;
				HeartBeat.On(); //打开心跳定时
			}
			if (strstr((char *)DataPointer.Data, "Test") != NULL)
				break;

			xSemaphoreTake(NetworkSendDone, 0);
			if(Network.SendDataPrepare(DataPointer.Length)) //准备上传
			{
				DMA_Send(&DataPointer);						    //发送数据
				xSemaphoreTake(NetworkSendDone, portMAX_DELAY); //获取发送完成信号量
				xSemaphoreGive(uploadSucc);						//给出上传成功信号量
			}
			break;
		}
		if (DataPointer.isDelete)	   //如果需要回收内存
			delete[] DataPointer.Data; //回收数据内存
	}
}

void srvNetworkRx(void *para)
{
	while (true)
	{
		xSemaphoreTake(NetworkRecive, portMAX_DELAY); //等待中断发出网络收到信号
		cout << "NET RX" << endl;
		cout.Printf("0x%02X 0x%02X", *NetworkData, *(NetworkData + 1));
		for (int i = 0; i < *(NetworkData + 1); i++)
			cout.Printf(" 0x%02X", NetworkData[i + 2]);
		cout << endl << endl;
		switch (*NetworkData)
		{
		case Login_response: //登录回复
			if ((EDP_Get_Login_Info(NetworkData) == Success) or (EDP_Get_Login_Info(NetworkData) == Already_Login))
				isLogin = true;
			break;

		case Connect_close: //关闭连接
		{
			isLogin = false;
			cout << "Connect Closed:" << EDP_Get_Close_Info(NetworkData) << endl;
			TestUpload(); //重新建立连接
		}
		break;

		case Command_request: //命令请求
		{
			cout << "Recive Reply" << endl;
			//EDP_CMD_Handle(NetworkData);//处理命令
			pEDP(Command) parse = (pEDP(Command))NetworkData; //
			parse->CMD_lenth = __REV(parse->CMD_lenth);		  //调整大小端顺序
			char Title[64] = {"0:/Reply/"}, *Reply = new char[512], *ch = parse->CMD;
			uint8_t index = 9;
			while (*ch != ':') //复制标题
				Title[index++] = *ch++;
			Title[index] = '\0';
			// strcat(Title, ".txt"); //添加扩展名
			parse->CMD_ID_lenth = parse->CMD_lenth - index + 8;
			memcpy(Reply, ch + 1, parse->CMD_ID_lenth); //复制内容

			FIL *fpReply = new FIL;
			cout << "Title:" << Title << endl;
			cout << "Reply:" << Reply << endl;
			auto fileName = new char[128];
			for (auto i = 0;i < 100;i++)
			{
				memset(fileName, 0, 128);
				snprintf(fileName, 128, "%s-%d.txt", Title, i);
				res = f_open(fpReply, fileName, FA_CREATE_NEW | FA_WRITE);
				if(res == FR_EXIST)
					continue;
				else if(res == FR_OK)
					break;
				else
					cout << "f_open fail" << "res:" << res << endl << __FILE__ << ':' << __LINE__ << endl;
			}
			delete[] fileName;
			res = f_write(fpReply, Reply, parse->CMD_ID_lenth, &parse->CMD_lenth);
			if (res != FR_OK)
				cout << "f_open fail" << "res:" << res << endl << __FILE__ << ':' << __LINE__ << endl;
			delete[] Reply; //回收内存
			f_close(fpReply);
			delete fpReply;
		}
		break;

		case Ping_response:
		{
			cout << "Recive Ping Response" << endl;
		}
		break;

		default:
			cout << "Net Message Type Error:" << *NetworkData << endl;
			break;
		}
		Network.ClearBuffer();
	}
}
void GUI_Task(void *para)
{
	while (true)
	{
		GUI_TOUCH_Exec();
		GUI_Delay(10);
	}
}
void SmartConfig_Task(void *para)
{
	char SSIDBuf[64];
	while (true)
	{
		cout << "Start Smart Config" << endl;
		if (Network.CheckReturn("SMART SUCCESS", 5000))
		{
			isConfigSucc = true;							  //标记配网成功
			auto dp = strstr((char *)Network.Buffer, "SSID"); //搜索SSID
			if (dp != nullptr)								  //找到
			{
				memset(SSIDBuf, 0, sizeof(SSIDBuf));
				sscanf(dp, "SSID:%s\r\n", SSIDBuf); //读入SSID并保存
				//显示SSID
				TEXT_SetText(thWIFI, SSIDBuf);
				strcpy(Config.WIFIName, SSIDBuf);
			}
			vTaskDelete(nullptr); //删除当前线程
		}
	}
}
/***************************************************************************/
int main()
{
	RCC::AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
	GPIO_Init();
	DMA_Init();
	TIM_Init();
	Interrupt_Init();
	cout << "Start" << endl;
	StartMesuare = xSemaphoreCreateBinary();				  //创建开始测量信号量
	NetworkRecive = xSemaphoreCreateBinary();				  //创建网络收到信号量
	NetworkSendDone = xSemaphoreCreateBinary();				  //创建网络发送完成信号量
	NewDataReady = xSemaphoreCreateBinary();				  //创建MAX30102信号量
	uploadSucc = xSemaphoreCreateBinary();				  	  //创建上传成功信号量
	NetworkUpload = xQueueCreate(10, sizeof(UpLoadPacket_t)); //创建网络上传数据队列,传递数据指针
	Delay.ms(3000);
	
	Heart.DeInit();
	
	cout << "SetFeedBack:" << Network.SetFeedBack(false) << endl;
	cout << "SetAutoCon:" << Network.SetWIFIAutoConnect(true) << endl;

	cout << SDCard::ResaultToString[Card.Init()] << endl;
	res = f_mount(&fs, "0:", 0);
	if (res != FR_OK)
		cout << "f_mount Fail:" << res << endl;

	WM_SetCreateFlags(WM_CF_MEMDEV);
	MainTask();

	xTaskCreate(srvNetworkRx, "srvNetworkRx", 512, nullptr, 4, nullptr); //创建网络接收线程,优先级4
	xTaskCreate(srvNetworkTx, "srvNetworkTx", 512, nullptr, 3, nullptr); //创建网络发送线程,优先级3
	xTaskCreate(SensorTask, "Sensor", 640, nullptr, 2, nullptr);		 //创建传感器线程,优先级2
	xTaskCreate(GUI_Task, "Touch Task", 2048, nullptr, 1, nullptr);		 //创建GUI线程,优先级1
	
	TestUpload(); //建立TCP并登录
	
	isSystemRun = true;
	cout << "Start Ker" << endl;
	vTaskStartScheduler(); //系统内核启动
	while (true);
}
